<template>
  <div class="app-container">
    <el-form ref="form" :model="car" label-width="120px">

      <el-form-item label="车牌号">
        <el-input v-model="car.carNum" />
      </el-form-item>
      <el-form-item label="汽车品牌">
        <el-input v-model="car.brand" />
      </el-form-item>
      <el-form-item label="汽车颜色">
        <el-input v-model="car.color" />
      </el-form-item>
      <el-form-item label="数据状态">
        <el-radio-group v-model="car.status">
          <el-radio label="正常"/>
          <el-radio label="失效" />
        </el-radio-group>
      </el-form-item>

      <el-form-item>
        <el-button type="primary"  @click="onSubmit">新增车辆</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      car: {
        carNum: '',
        brand: '',
        color:''
      }
    }
  },
  methods: {
    onSubmit() {
      // 请求接口 实现用户新增接口的调用
      request({
        url:"http://127.0.0.1:8080/api/car/save.do",
        method: "POST",
        data:this.car
      }).then(res=>{
        if(res.code==0){
          //跳转到列表页面
          this.$router.push("/carlist");
        } else {
          alert(res.msg)
        }
      })
    },
    checkPass() {},
    onCancel() {
      this.$message({
        message: '取消车辆的新增',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

